package com.example.waimai.contraller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.waimai.common.R;
import com.example.waimai.pojo.Orders;
import com.example.waimai.service.ServiceOrders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/order")
@RestController
public class OrdersContraller {
    @Autowired
    private  ServiceOrders serviceOrders;


    //分页查询
    @GetMapping("/page")
    public R<Page> page( int page,int pageSize){
        Page<Orders> pageinfo=new Page(page,pageSize);
        LambdaQueryWrapper<Orders> lqw=new LambdaQueryWrapper<>();
        lqw.orderByDesc(Orders::getOrderTime);
        Page<Orders> page1 = serviceOrders.page(pageinfo);
        return R.success(page1);
    }


    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("购物车信息:{}",orders);
        serviceOrders.submit(orders);
        return R.success("下单成功");
    }
}
